﻿
Partial Class Transcript
    Inherits CPage

    Public ReadOnly Property ProductId As Integer
        Get
            Return CWeb.RequestInt("productId")
        End Get
    End Property
    Public ReadOnly Property Html As Boolean
        Get
            Return CWeb.RequestBool("html", True)
        End Get
    End Property


    Protected Overrides Sub PageInit()
        Dim p As CProduct = CProduct.Cache.GetById(ProductId)

        If Html Then
            Dim k As New CKindle(EFormat.HTML)
            Response.ContentType = "text/html"
            Response.Write(k.Display(p))
            Exit Sub
        End If

        Response.ContentType = "text/plain"

        If IsNothing(p) Then
            Response.Write("Product not found")
        ElseIf Not p.HasTranscript AndAlso Not p.Children.HavingTranscripts.Count > 0 Then
            Response.Write("Transcript not available")
        ElseIf Html Then
            Response.Write(New CKindle(EFormat.HTML).Display(p))
        Else
            Response.AddHeader("content-disposition", "attachment;filename=" & p.ProductName & ".txt")
            Response.Write(p.ProductTranscription)
        End If
    End Sub

End Class
